home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / aie8911.zip / BACK.ARI < prev    next >
Text File  |  1989-08-27  |  4KB  |  144 lines

  1. %%%%%%%%%%%%%%%%%%%% end auto gened decs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.  
  3. :- visible do_goal / 1.
  4. :- extrn   zzz_displayed / 1 : interp.
  5.  
  6.  
  7. /************************* do_goal / 1 *************************************/
  8. /*
  9. executes a Prolog goal, using stubs as well as code
  10. */
  11.  
  12.                      % if a stub is there and it
  13.                      % should be used (e.g. no Prolog code
  14.                      % for process, use the stub
  15. do_goal( Goal ) :-
  16.                      % is there a stub for the Goal
  17.     has_stub( Goal, Frame ),
  18.                      % should the stub be used?
  19.     use_the_stub_q(  Frame),
  20.     !,
  21.                      % then definitely use the stub
  22.     do_stub( Frame).
  23.  
  24.                      % If the goal is user-defined to
  25.                      % fail, then make it fail (this
  26.                      % lets the user explore the specified
  27.                      % system)
  28. do_goal( Goal ) :-
  29.     call( failing_goal( Goal)),
  30.     !,
  31.     fail.
  32.  
  33.                      % If the goal is defined in Prolog
  34.                      % source code, then
  35.                      % interpret it using the definition
  36.                      % of Prolog
  37. do_goal( Goal) :-
  38.                      % Is the goal defined in Prolog code?
  39.      defined_as_prolog_goal( Goal ),
  40.                      % display goal purpose from stub
  41.      display_goal_purpose( Goal ),
  42. %    log_write( $Goal = $), log_write(Goal),
  43. %    log_nl,
  44.                      % get body of rule defining Goal
  45.      clause( Goal, Body),
  46. %    log_write( $Body = $), log_write(Body),
  47. %    log_nl,
  48.                      % execute rule body
  49.      do_body( Body).
  50.  
  51.                      % Execute goals defined by Prolog system
  52.                      % code
  53. do_goal( Goal) :-
  54.                      % Make sure there is no source code
  55.                      % definition
  56.      not defined_as_prolog_goal( Goal ),
  57.                      % Try the goal using Prolog system
  58.                      % procedures
  59.      call( Goal ).
  60.  
  61.  
  62. /************************* do_goal helpers *********************************/
  63.  
  64.                      % Is a goal defined as source code?
  65. defined_as_prolog_goal( Term ) :-
  66.         clause( Term, _),
  67.         !.
  68.  
  69.        % do_body executes Prolog rule bodies
  70.  
  71.                      % Is a goal defined as source code?
  72. do_body( true ) :- !.
  73.  
  74.                      % Execute 'ands' of subgoals
  75.                      % in rule bodies
  76. do_body( ( H , Rest) ) :-
  77.       !,
  78.       do_and( H, Rest).
  79.  
  80.                      % Execute a single goal, by calling
  81.                      % do_goal
  82. do_body( Term) :-
  83.       do_goal( Term).
  84.  
  85.        % do_and executes 'ands' of goals
  86. do_and( Head , Rest) :-
  87.                      % Try the first goal
  88.       do_goal( Head),
  89.                      % Try the other goals
  90.       do_body( Rest).
  91.  
  92. /************************* display_goal_purpose ****************************/
  93.  
  94.  
  95. display_goal_purpose( Goal ) :-
  96.       display_this_goal_q( Goal),
  97.       display_goal_hlpr( Goal),
  98.        !.
  99. display_goal_purpose( _    ).
  100.  
  101. display_goal_hlpr( Goal) :-
  102.     has_stub( Goal, Frame ),
  103.     !,
  104.     display_purpose( Frame ).
  105.  
  106. display_goal_hlpr( Goal) :-
  107.     log_write($Executing $),
  108.     log_write( Goal),
  109.     log_write($.$),
  110.     log_nl.
  111.  
  112. display_this_goal_q( Goal) :-
  113.       functor( Goal, Name, Arity),
  114.       display_this_functor( Name / Arity),
  115.       !.
  116.  
  117. display_this_functor( Functor      ) :-
  118.       call( zzz_displayed( Functor)).
  119.  
  120. display_this_functor( Name / _     ) :-
  121.       display_this_functor( Name ),
  122.       !.
  123.  
  124.  
  125. /*********************** test for do_goal ******************************
  126.  
  127. test :-
  128.    do_goal( goal( X, Y)).
  129.  
  130. goal(X, Y) :-
  131.     foo(X),
  132.     ho(X,Y),
  133.     log_write(X),
  134.     log_nl,
  135.     log_write(Y).
  136.  
  137. foo(1).
  138. foo(2).
  139. ho( 2,3).
  140.  
  141. failing_goal(  log_write(3)).
  142.  
  143. ********************* end of file ***************************************/
  144.